import router from './router'
import store from './store'
import NProgress from 'nprogress' // Progress 进度条
import 'nprogress/nprogress.css'// Progress 进度条样式
import { Message } from 'element-ui'
import { getToken } from '@/utils/auth' // 验权

const whiteList = ['/login'] // 不重定向白名单
router.beforeEach((to, from, next) => {
  NProgress.start()
  if (getToken()) {
    if (to.path === '/login') {
      debugger




     NProgress.done() // if current page is dashboard will not trigger	afterEach hook, so manually handle it
    } else {
      next()
      // debugger
      // var userInfo=JSON.parse(localStorage.getItem("userInfo"))
      // if(userInfo){
      //   var roleId=userInfo.roleId
      //   if(roleId==1){
      //     next('/kkg/product')
      //   }else if(roleId==2){
      //     next('/kkg/goods/' )
      //   }else if(roleId==3){
      //     next('/kkg/orderForm' )
      //   }else if(roleId==4){
      //     next('/kkg/orderForm')
      //   }
      //   next()
      // }
    }
  } else {
    if (whiteList.indexOf(to.path) !== -1) {
      next()
    } else {
      next('/login')
      NProgress.done()
    }
  }
})

router.afterEach(() => {
  NProgress.done() // 结束Progress
})
